// JavaScript Document
var setting = {
	check: {
		enable: true
	},
	data: {
		simpleData: {
			enable: true
		}
	},
	callback: {
			onClick: onClick
		}
};
var zNodes =[
	{ id:1, pId:0, name:"经营树",title:"", open:true, iconSkin:"dw",levels:"a0"},
		{ id:11, pId:1, name:"1",title:"", open:true, iconSkin:"dw",levels:"a1"},
			{ id:111, pId:11, name:"22",title:"",open:true, iconSkin:"xz",levels:"a2"},
				{ id:1111, pId:111, name:"30",title:"",isHidden:true, iconSkin:"zd",levels:"a3"},
				{ id:1112, pId:111, name:"31",title:"", iconSkin:"zd",levels:"a3"},
				{ id:1113, pId:111, name:"32",title:"", iconSkin:"zd",levels:"a3"},
				{ id:1114, pId:111, name:"33",title:"", iconSkin:"zd",levels:"a3"},		
];


function onClick(event, treeId, treeNode, clickFlag) {
	
	var Level=treeNode.levels;
	var	zTree = $.fn.zTree.getZTreeObj("treeDemo");
	var sid = $("#treeDemo").attr("selctId");  //前一次选中的节点Id
	var tid = treeNode.tId;					   //当前选中的节点ID	
	if (null != sid && "" != sid) {
		var sId = zTree.getNodeByTId(sid);    //节点在 zTree 内的唯一标识,
		var lev=sId.levels;					  //通过sId判断与之对应的lev	
		if(lev=="a0" || lev=="a1"){
			sId.iconSkin = "dw";
		}
		if(lev=="a2"){
			sId.iconSkin = "xz";
		}
		if(lev=="a3"){
			sId.iconSkin = "zd";
		}
		zTree.updateNode(sId);
	}
	if(Level=="a0"){
		treeNode.iconSkin = "dwc";
	}
	if(Level=="a1"){
		treeNode.iconSkin = "dwc";
	}
	if(Level=="a2"){
		treeNode.iconSkin = "xzc";
	}
	if(Level=="a3"){
		treeNode.iconSkin = "zdc";
	}
	zTree.updateNode(treeNode);
	$("#treeDemo").attr("selctId", treeNode.tId);
}
function showNodes() {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	nodes = zTree.getNodesByParam("isHidden", true);
	zTree.showNodes(nodes);
}
function hideNodes() {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	nodes = zTree.getSelectedNodes();
	if (nodes.length == 0) {
		alert("请至少选择一个节点");
		return;
	}
	zTree.hideNodes(nodes);
}

$(document).ready(function(){
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	$("#hideNodesBtn").bind("click", {type:"rename"}, hideNodes);
	$("#showNodesBtn").bind("click", {type:"icon"}, showNodes);
});	